package com.wh.controller.instorehouse;

import com.wh.pojo.Receiving;
import com.wh.service.instorehouse.ReceivingService;
import com.wh.vo.Options;
import com.wh.vo.PageResult;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/receiving/")
public class ReceivingController {

    @Autowired
    private ReceivingService receivingService;

    @GetMapping("getOptions")
    public SysResult getOptions(){
        List<Options> optionsList = receivingService.getOptions();
        return SysResult.success(optionsList);
    }

    @PostMapping("addReceiving")
    public SysResult addReceiving(@RequestBody Map<String,String> map){
        System.out.println(map);
        receivingService.addReceiving(map.get("id"),map.get("user"));
        return SysResult.success();
    }

    @GetMapping("getReceiving")
    public SysResult getReceiving(PageResult pageResult){
        pageResult = receivingService.getReceiving(pageResult);
        return SysResult.success(pageResult);
    }

    @PutMapping("updataReceiving")
    public SysResult updataReceiving(@RequestBody Receiving receiving){
        receivingService.updataReceiving(receiving);
        return SysResult.success();
    }

    @DeleteMapping("deleteReceiving/{receivingId}/{purchaseId}")
    public SysResult deleteReceiving(@PathVariable String receivingId,@PathVariable String purchaseId){
        receivingService.deleteReceiving(receivingId,purchaseId);
        return SysResult.success();
    }
}
